package com.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

@Configuration
public class FileConfig {
    @Bean
    public FileConfigure getFileConfigure() throws IOException {
        FileConfigure fileConfigure = new FileConfigure();
        File configFile = new File("config.properties");
        if (!configFile.exists()) {
            configFile.createNewFile();
        }
        System.out.println(configFile.isFile());
        Properties properties = new Properties();
        FileInputStream fileInputStream = new FileInputStream(configFile);
        properties.load(fileInputStream);
        fileInputStream.close();

        String basePath = properties.getProperty("basePath");
        System.out.println(basePath);
        fileConfigure.setBasePath(basePath);

        return fileConfigure;
    }
}
